package com.project.mybus;

import java.util.List;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;



public class BusAdapter extends ArrayAdapter<Bus> {
	
	private final List<Bus> buses;

	
	public BusAdapter(Context context, int resource, List<Bus> objects) {

	    super(context, resource, objects);

	    this.buses = objects;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = convertView;
		
		BusView busView = null;

		if (rowView == null) {
			// Get a new instance of the row layout view
			LayoutInflater inflater = LayoutInflater.from(getContext());
			rowView = inflater.inflate(R.layout.stop_item, null);

			// Hold the view objects in an object,
			// so they don't need to be re-fetched
			busView = new BusView();
			busView.bus_name = (TextView) rowView
					.findViewById(R.id.bus_name);
			//busView.bus_time = (TextView) rowView
			//		.findViewById(R.id.bus_time);
			// Cache the view objects in the tag,
			// so they can be re-accessed later
			rowView.setTag(busView);
		} else {
			busView = (BusView) rowView.getTag();
		}

		// Transfer the stock data from the data object
		// to the view objects
		Bus bus = (Bus) buses.get(position);
		busView.bus_name.setText(bus.getBus_name());
		//busView.bus_time.setText(bus.getBus_time());

		return rowView;
	}

	protected static class BusView {
		protected TextView bus_name;
		//protected TextView bus_time;
	}
}
